<template>
	<view class="content">
		<view class="dis_sb p20 bgfff pr">
			<image :src="data.touxiang" mode="aspectFill" class="rad50 pic mr20"></image>
			<view class=' w100 '>
				<view class="clo-blue f32 dis_sc pb10"> <text  class="fwb">{{name}} </text> <text class="iconfont f50 clo-444 pl20" @click="toggle('center')">&#xe6bd;</text> </view>
				<view class="clo-999 f28">TEL:{{data.tel}}</view>
			</view>
			<!-- <text class="iconfont clo-blue bgeee rad50 set">&#xe6e7;</text> -->
		</view>
		
		<view class="bgfff list pl20 pr20 pt20 mt20 dis_sc fww">
			<view @click="tapLink('/pages/index/team')">
				<image  src="../../static/icon1.png" mode="widthFix"></image>
				<view class="clo-444 mt5">我的团队</view>
			</view>
			<view @click="tapLink('/pages/index/withdrawal')">
				<image src="../../static/icon2.png" mode="widthFix"></image>
				<view class="clo-444 mt5">我的钱包</view>
			</view>
			<view @click="tapLink('/pages/index/income')">
				<image src="../../static/icon3.png" mode="widthFix"></image>
				<view class="clo-444 mt5">收益明细</view>
			</view>
<!-- 			<view @click="tapLink('/pages/index/order')">
				<image src="../../static/icon4.png" mode="widthFix"></image>
				<view class="clo-444 mt5">我的订单</view>
			</view> -->
<!-- 			<view @click="logout()">
				<image src="../../static/icon5.png" mode="widthFix"></image>
				<view class="clo-444 mt5">退出登录</view>
			</view> -->
			
		</view>
		<uni-popup ref="popup" background-color="#fff" >
			<view class="popup-content pt2020" >
				<view class="tac f34 line2">邀请好友</view>
				<image :src="invite.pic" mode="aspectFit"></image>
				<view class="tac line2">邀请码：{{invite.code}}</view>
				<button class="bgeee clo-999 f28 mt20" v-if="invite.pic" @click="down(invite.pic)">保存二维码</button>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {payLogin,userInfo} from '@/utils/api'
	export default {
		data() {
			return {
				invite:{					
					pic:'',
					code:''
				},
				data:{
					
					type: 'center',
					name:"王美丽",
					touxiang:"../../static/logo.png",
					tel:"13643168526",
					
				},
				name:'',
				provider:'',
				// fenxiao_url:''
			}
		},
		onLoad(e) {
			if(e.user_id){
				this.user_id=e.user_id
			}
			// this.name=uni.getStorageSync('name')
			
			let token=uni.getStorageSync('token')
			if(!token){
				uni.getProvider({service: 'oauth'}).then(res=>{
					// console.log(res.provider[0],'看登陆了')
					this.provider=res.provider[0]
					
					uni.login({
						provider:this.provider
					}).then(loginRes=>{
						console.log(loginRes,'看一下授权登录信息')
						var data={'code':loginRes.code,'provider':this.provider}
						payLogin(data).then(res=>{
							let data=res.data
							uni.setStorageSync('token',data.access_token)
							this.getInfo()
						})
					})
				})	
			}else{
				this.getInfo()
			}
		},
		methods: {
			getInfo(){
				userInfo().then(res=>{
					let data = res.data
					this.invite.pic = data.fenxiao_url
					this.invite.code = data.fenxiao_code
					this.name=data.name
					console.log(data)
				})
			},
			tapLink(e){
				uni.navigateTo({
					url:e
				})
			},
			toggle(type) {
				this.type = type
				// open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
				this.$refs.popup.open(type)
			},
			logout(){
				 uni.removeStorage({
				    key: 'userToken',
				    success: function() {
				      uni.showToast({
				      	title: '退出登录',
				      	duration: 2000
				      })
				      // 可以在这里跳转到登录页面
				      // uni.redirectTo({
				      //   url: '/pages/login/login'
				      // });
				    },
				    fail: function() {
				      console.log('清除Token失败');
				    }
				  });
			},
			down(url){
				console.log(url);
				uni.showLoading({
					title:'请稍后',
				})
				uni.downloadFile({
					url:url,
					success(res) {
						console.log(res);
						if (res.statusCode === 200) {
							uni.hideLoading()
							uni.saveImageToPhotosAlbum({
								filePath: res.tempFilePath,
								success: function () {
									uni.showToast({
										title:'下载成功',
										icon:'none'
									})
								},
								fail: function(err) {
								  console.log(err);
								}
							});
						}
					}
				})
			}
		}
	}
</script>

<style>
	.pic {width: 120rpx; height: 120rpx; border:10rpx solid rgba(255,255,255,0.3); box-shadow: 0 0 10rpx #eee; flex-shrink: 0; }
	.list image {width: 80rpx; height: 80rpx;}
	.list>view {text-align: center; width: 25%; margin-bottom: 20rpx;}
	.set {position: absolute; font-size: 35rpx; padding: 6rpx; right: 30rpx; top: 36%;}
	.popup-content image {width: 350rpx; height: 350rpx;}
	.popup-content {padding: 20rpx 50rpx;  }
</style>
